package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.ExpertConsultation.ExpertBean;
import com.project.mapper.IExpertMapper;
import com.project.service.IExpertService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional

public class IExpertServiceImpl extends ServiceImpl<IExpertMapper, ExpertBean> implements IExpertService {
    @Override
    public IPage<ExpertBean> findCutExpert(int pageNo, int pageSize, String expertName, String expertSpecialty, String expertUnit) {

        Page<ExpertBean> page = new Page<>(pageNo,pageSize);

        QueryWrapper wrapper = new QueryWrapper<>();

        if (expertName!=null){
            wrapper.like("expert_name",expertName);
        }
        if (expertSpecialty!=null){
            wrapper.like("expert_specialty",expertSpecialty);
        }
        if (expertUnit!=null){
            wrapper.like("expert_unit",expertUnit);
        }

        return this.baseMapper.selectPage(page,wrapper);
    }

    @Override
    public void addExpert(ExpertBean expertBean) {

        this.baseMapper.insert(expertBean);
    }

    @Override
    public ExpertBean findExpertById(int expertId) {


        return this.baseMapper.selectById(expertId);
    }

    @Override
    public void updateExpert(int expertId, String expertTel, String expertJob, String expertUnit, String expertEmail) {

        ExpertBean expertBean = new ExpertBean();
        expertBean.setExpertId(expertId);
        expertBean.setExpertTel(expertTel);
        expertBean.setExpertJob(expertJob);
        expertBean.setExpertEmail(expertEmail);

        this.baseMapper.updateById(expertBean);
    }

    @Override
    public void delExpert(int expertId) {

        this.baseMapper.deleteById(expertId);

    }

    @Override
    public List<ExpertBean> findAllexp() {
        return this.baseMapper.selectList(null);
    }
}
